package testdomainsupermarket;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import conditionsAPI.ConditionDuplicatedException;
import conditionsAPI.SimpleDomainCondition;

public class PerfumeryItemCondition extends SimpleDomainCondition{

	private Collection<LineItem> lineItems;
	
	public PerfumeryItemCondition(String id)
			throws ConditionDuplicatedException {
		super(id);
		this.lineItems = new ArrayList<LineItem>();
	}
	
	private boolean hasPerfumeryItems(){
		Iterator<LineItem> lineItemsIterator = this.lineItems.iterator();
		while (lineItemsIterator.hasNext()){
			LineItem lineItem = lineItemsIterator.next();
			if (lineItem.getCategory().equals(LineItem.Categories.PERFUMERY)){
				return true;
			}
		}
		return false;
	}

	@Override
	public boolean checkConditionState(Object domainObject) {
		LineItem lineItem = (LineItem) domainObject;
		this.lineItems.add(lineItem);
		return hasPerfumeryItems();
	}
	
	protected boolean resetToInitialState(){
		this.lineItems.clear();
		return false;
	}
}
